package models

import (
	"gorm.io/gorm"
	"house-src/basic/config"
	"time"
)

// 预约
type Reservation struct {
	gorm.Model
	CustomerId int        `json:"customer_id" gorm:"type:int;comment:'客户id'"`
	CleanerId  int        `json:"cleaner_id" gorm:"type:int;comment:'清洁师id'"`
	Title      string     `json:"title" gorm:"type:varchar(30);comment:'标题'"`
	Price      float64    `json:"price" gorm:"type:decimal(10,2);comment:'价格'"`
	Address    string     `json:"address" gorm:"type:varchar(100);comment:'服务地址'"`
	Area       int        `json:"area" gorm:"type:int;comment:'服务面积'"`
	Difficulty float64    `json:"difficulty" gorm:"type:decimal(10,2);comment:'难度系数'"`
	StartTime  *time.Time `json:"start_time" gorm:"type:datetime;comment:'开始时间'"`
	Duration   float64    `json:"duration" gorm:"type:decimal(10,2);comment:'预约时长'"`
	Status     int        `json:"status" gorm:"type:int;comment:'状态 1-未开始 2-已结束'"`
}

func (r *Reservation) TableName() string {
	return "reservation"
}

func (r *Reservation) AddReservation() error {
	return config.DB.Create(&r).Error
}

func (r *Reservation) GetReservation(id int) error {
	return config.DB.Model(&Reservation{}).Where("id = ?", id).Limit(1).Find(&r).Error
}
